#include "World.hh"
#include "utils.hh"

static GLfloat wDiff[] = {0.18275, 0.17, 0.22525}; 
static GLfloat wAmb[] = {0.05375, 0.05, 0.06625};
static GLfloat wSpecular[] = {0.332741, 0.328634, 0.346435};
static GLfloat shininess = 0.3;

World::World()
{
	myCollisionConfiguration = new btDefaultCollisionConfiguration();
  	myDispatcher = new btCollisionDispatcher(myCollisionConfiguration);
  	myBroadphase = new btDbvtBroadphase();
  	mySequentialImpulseConstraintSolver = new btSequentialImpulseConstraintSolver;
  	myWorld = new btDiscreteDynamicsWorld(myDispatcher,myBroadphase,mySequentialImpulseConstraintSolver,myCollisionConfiguration);
  	myWorld->setGravity( btVector3(0,-10,0) );

  	btCollisionShape* shape_sol = new btBoxShape( btVector3(100,1,100) );
	myTransform.setIdentity();
	myTransform.setOrigin( btVector3(0,0,0) );
	btVector3 localInertiaSol(0,0,0);
	mass = 0;
	myMotionState_Sol = new btDefaultMotionState(myTransform);
	btRigidBody::btRigidBodyConstructionInfo sol_info( mass, myMotionState_Sol, shape_sol, localInertiaSol );
	body_sol = new btRigidBody(sol_info);
	myWorld->addRigidBody(body_sol); 
}

btTransform *World::getTransform()
{
	return &myTransform;
}

void World::addRigidBody(btRigidBody *body)
{
	myWorld->addRigidBody(body);
}

void World::draw(float time)
{
	glEnable(GL_COLOR_MATERIAL);
	myWorld->stepSimulation(0.04);
	glMaterialfv(GL_FRONT, GL_AMBIENT, wAmb);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, wDiff);
	glMaterialfv(GL_FRONT, GL_SPECULAR, wSpecular);
	glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
	slBox(100,1,100);

}

World::~World()
{

}